package com.qiusuo0226.self.pojo.dto;

import com.alibaba.fastjson2.JSONObject;
import com.qiusuo0226.common.util.BeanContext;
import com.qiusuo0226.common.util.ConvertTool;
import com.qiusuo0226.platform.annotation.valid.ValidType;
import com.qiusuo0226.security.config.SecurityProperty;
import com.qiusuo0226.security.util.AesTool;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * 个人密码管理 新增 业务模型
 * @author qiusuo
 * @date 2023/7/15 22:31
 */
@Getter
@Setter
@ToString
@NoArgsConstructor
public class PasswordManageAddDTO implements Serializable {

    private static final long serialVersionUID = 4170365081880736199L;

    /**
     * 创建者唯一标识
     */
    @NotNull(message = "创建者唯一标识不能为Null")
    private Long creater;

    /**
     * 软件名称
     */
    @NotBlank(message = "软件名称不能为Null")
    @Length(min = 1, max = 50, message = "软件名称长度应该在1~50之间")
    private String softwareName;

    /**
     * 网址
     */
    @Length(min = 0, max = 255, message = "网站网址长度应该在0~255之间")
    private String website;

    /**
     * 账号
     */
    @NotBlank(message = "账号不能为Null")
    @Length(min = 1, max = 100, message = "账号长度应该在1~100之间")
    private String account;

    /**
     * 密码
     */
    @NotBlank(message = "密码不能为Null")
    @Length(min = 1, max = 500, message = "密码长度应该在1~500之间")
    private String password;

    /**
     * 加密方式
     */
    @ValidType(types = {"0","1","2","3"}, message = "密码加密类型错误")
    private String encryptType;

    /**
     * 加密所需要的密钥信息内容
     */
    private JSONObject encryptKeyInfo;

    /**
     * 描述
     */
    @Length(min = 0, max = 255, message = "描述长度应该在0~255之间")
    private String description;

    /**
     * 标签
     */
    @Length(min = 0, max = 100, message = "标签长度应该在0~100之间")
    private String tags;

    /**
     * 入参解密
     */
    public void decrypt() throws Exception {
        SecurityProperty property = BeanContext.getBean(SecurityProperty.class);
        password = AesTool.decryptECB(ConvertTool.base64DecodeToBytes(password), ConvertTool.hexToBytes(property.getAesKey()));
    }

    /**
     * token
     */
    private String token;


}
